/*
 * @lc app=leetcode.cn id=643 lang=cpp
 *
 * [643] 子数组最大平均数 I
 */

// @lc code=start
class Solution
{
public:
  double findMaxAverage(vector<int>& nums, int k)
  {
    int n = nums.size();
    double start = 0.0f, end = 0.0f;
    for (int i = 0; i < k; ++i)
      end += nums[i];
    double ma = end / k;
    int slow = 0;
    for (int fast = k; fast < n; ++fast, ++slow) {
      end += nums[fast];
      start += nums[slow];
      ma = max(ma, (end - start) / k);
    }
    return ma;
  }
};
// @lc code=end
